﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ROrganizer.UI.Controllers;
using ROrganizer.UI.Forms.Core;

namespace ROrganizer.UI.Forms
{
    internal partial class FileDetailsForm : Form
    {
        private readonly FileDetailsFormController controller;

        public FileDetailsForm(string path)
        {
            this.controller = new FileDetailsFormController(path);
            this.InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.tbFile.Text = this.controller.File;
            this.tbHash.Text = this.controller.Hash;
            this.tbImdbLink.Text = this.controller.Link;

            this.llblOpenImdbLink.Enabled = this.controller.CanOpenImdbLink();
            this.btnCommit.Enabled = this.controller.CanCommit();
        }

        private void OnOpenFile(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.ExecuteAndWatch(this.controller.OpenFile);
        }

        private void OnOpenImdbLink(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.ExecuteAndWatch(this.controller.OpenImdbLink);
        }

        private void OnImdbLinkChanged(object sender, EventArgs e)
        {
            this.controller.Link = this.tbImdbLink.Text;
            this.llblOpenImdbLink.Enabled = this.controller.CanOpenImdbLink();
            this.btnCommit.Enabled = this.controller.CanCommit();
        }

        private void OnCommit(object sender, EventArgs e)
        {
            this.ExecuteAndWatch(this.Commit);
        }

        private void Commit()
        {
            this.controller.Commit();
            this.DialogResult = DialogResult.OK;
        }
    }
}
